package game;

import java.util.ArrayList;
import java.util.Scanner;

public class Game extends Thread {

	/**
	 * @param args
	 * 
	 */
	public ArrayList<Player> players;
	public Player me;
	private static Game instance;
	private String name;
	private ScoreList list;
	private Gameplayer g;
	private boolean visible = true;

	private Game() {

	}

	public static Game getInstance() {
		if (instance == null) {
			instance = new Game();
		}

		return instance;
	}

	public void run() {
		players = new ArrayList<Player>();
		me = new Player(name);
		players.add(me);

		setList(new ScoreList(players));
		getList().setVisible(true);
		setG(new Gameplayer(me, getList()));
		
	}

	public boolean isVisible() {
		return visible;
	}
	public void setVisible(boolean visible) {
		this.visible = visible;
	}

	public String getPlayerName() {
		return me.getName();
	}
	
	public void initPlayerName(String navn) {
		name = navn;
	}
	
	public String getPlayerColor() {
		return "" + me.color;
	}
	
	public Player findPlayer(String name) {
		Player result = null;
		for(Player p : players) {
			if(p.getName().equals(name)) {
				result = p;
			}
		}
		if(result == null) {
			throw new Error("Player not found, failing!");
		}
		return result;
	}

	public ScoreList getList() {
		return list;
	}

	public void setList(ScoreList list) {
		this.list = list;
	}

	public Gameplayer getG() {
		return g;
	}

	public void setG(Gameplayer g) {
		this.g = g;
	}

	public void spawnBonus() {
		
	}

	public void setPlayerColor(String color) {
		me.setColor(Integer.parseInt(color));
	}
}